<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    th{
      padding-left: 30px;
    }
    .allCheck{
      width: 80px;
    }
  </style>
</head>
<body>
  <table>
    <tr>
      <th class="allCheck">
        <input type="checkbox" id="checkAll"> <span class="all">全选</span>
      </th>
      <th>商品</th>
      <th>商家</th>
      <th>价格</th>
    </tr>
    <tr>
      <th>
        <input type="checkbox" name="" id="checkbox">
      </th>
      <th>火鸡面</th>
      <th>88</th>
      <th>10.0</th>
    </tr>
    <tr>
      <th>
        <input type="checkbox" name="" id="checkbox">
      </th>
      <th>鸭腿</th>
      <th>77</th>
      <th>12.5</th>
    </tr>
    <tr>
      <th>
        <input type="checkbox" name="" id="checkbox">
      </th>
      <th>辣条</th>
      <th>66</th>
      <th>3.2</th>
    </tr>
  </table>
  <script>
    const checkAll = document.querySelector('#checkAll')
    const checkbox = document.querySelectorAll('#checkbox')
    checkAll.addEventListener('click',function(){
      for(let i = 0; i < checkbox.length; i++){
        checkbox[i].checked = checkAll.checked
        }
    })
    for(let i = 0; i < checkbox.length; i++){
        checkbox[i].addEventListener('click',function(){
          let n = document.querySelectorAll('#checkbox:checked').length
            checkAll.checked = n === checkbox.length
        })
      }
      
  </script>
</body>
</html>